

using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Dynamic;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Abp.Linq;
using Abp.Linq.Extensions;
using Abp.Extensions;
using Abp.UI;
using Abp.Domain.Repositories;
using Abp.Domain.Services;

using Yozeev;
using Yozeev.BusinessLogic;
using Yozeev.Models;
using Yozeev.SystemConfig;
using Yozeev.UserManagerment.Users;
using Abp.Domain.Entities.Auditing;
using Yozeev.Help;

namespace Yozeev.BusinessLogic.DomainService
{
    /// <summary>
    /// Activity领域层的业务管理
    ///</summary>
    public class CommonDomainService : YozeevDomainServiceBase, IActivityManager
    {
		
		private readonly IRepository<BranchUser, Guid> _branchUserRepository;
		private readonly IRepository<Customer, Guid> _customerRepository;
		private readonly IRepository<Ticket, Guid> _ticketRepository;
		protected readonly IRepository<TicketDetail, Guid> _ticketDetailRepository;

		/// <summary>
		/// Activity的构造方法
		///</summary>
		public CommonDomainService( 
			IRepository<BranchUser, Guid> branchUserRepository
			, IRepository<Customer, Guid> customerRepository
			, IRepository<Ticket, Guid> ticketRepository
			, IRepository<TicketDetail, Guid> ticketDetailRepository
		)
		{
			_branchUserRepository = branchUserRepository;
			_customerRepository = customerRepository;
			_ticketRepository = ticketRepository;
			_ticketDetailRepository = ticketDetailRepository;
		}


		/// <summary>
		/// 初始化
		///</summary>
		public void InitActivity()
		{
			throw new NotImplementedException();
		}

		// TODO:编写领域业务代码

		/// <summary>
		/// 根据用户获取机构用户关系
		/// </summary>
		/// <param name="user"></param>
		/// <returns></returns>
		public BranchUser GetBranchUser(long userId)
		{
			return _branchUserRepository.GetAll().AsNoTracking().FirstOrDefault(m => m.UserId == userId);
		}
		/// <summary>
		/// 根据票价格获取票型
		/// </summary>
		/// <param name="ticketPrice"></param>
		/// <returns></returns>
		public Ticket GetTicket(TicketPrice ticketPrice) 
		{
			return _ticketRepository.GetAll().AsNoTracking().FirstOrDefault(m => m.Id == ticketPrice.TicketId);
		}
		/// <summary>
		/// 根据Id查询用户
		/// </summary>
		/// <param name="guid"></param>
		/// <returns></returns>
		public Customer GetCustomersById(Guid guid)
		{
			return _customerRepository.GetAll().AsNoTracking().FirstOrDefault(m => m.Id == guid);
		}

	}
}
